<include file="../header"/>
<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/repair/images/load-bee.png"/>
    </div>
    <div class="top">
        <p>
            <a href="javascript:history.back(-1)" class="iconfont icon-zuo fl-left"></a>
            <span class="pull-left text-center">添加地址</span>
            <a href="{BEESCRM::U('base/center/center',array('account_id'=>$accountId))}"
               class="iconfont icon-shouye text-right fl-right"></a>
        </p>
    </div>

    <p class="title">姓名</p>
    <p class="form-box">
        <input class="input" value="{BEESCRM:$addressInfo.real_name}" id="real_name"/>
    </p>
    <p class="title">联系方式</p>
    <p class="form-box">
        <input class="input" value="{BEESCRM:$addressInfo.mobile}" id="mobile"/>
    </p>


    <p class="title">园区选择</p>
    <p class="form-box">
        <select class="select" id="community">
            <option value="0">请选择园区</option>
            <volist name="community" id="vo">
                <option value="{BEESCRM:$vo.community_id}"
                <if condition="$addressInfo['community_id'] eq $vo['community_id']"> selected="selected"</if>
                >{BEESCRM:$vo.community_name}</option>
            </volist>
        </select>
        <span class="triangle"></span>
    </p>
    <p class="title">楼幢选择</p>
    <p class="form-box">
        <select class="select" id="building">
            <option value="0">请选择楼幢</option>
            <volist name="building" id="vo">
                <option value="{BEESCRM:$vo.building_id}"
                <if condition="$addressInfo['building_id'] eq $vo['building_id']"> selected="selected"</if>
                >{BEESCRM:$vo.building_name}</option>
            </volist>
        </select>
        <span class="triangle"></span>
    </p>

    <p class="title">楼层选择</p>
    <p class="form-box">
        <select class="select" id="floor">
            <option value="0">请选择楼层</option>
            <volist name="floor" id="vo">
                <option value="{BEESCRM:$vo.floor_id}"
                <if condition="$addressInfo['floor_id'] eq $vo['floor_id']"> selected="selected"</if>
                >{BEESCRM:$vo.floor_name}</option>
            </volist>
        </select>
        <span class="triangle"></span>
    </p>

    <p class="title">寝室选择</p>
    <p class="form-box">
        <select class="select" id="room">
            <option value="0">请选择寝室</option>
            <volist name="room" id="vo">
                <option value="{BEESCRM:$vo.room_id}"
                <if condition="$addressInfo['room_id'] eq $vo['room_id']"> selected="selected"</if>
                >{BEESCRM:$vo.room_name}</option>
            </volist>
        </select>
        <span class="triangle"></span>
    </p>


    <p class="title">详细地址</p>
    <p class="form-box">
        <input class="input" value="{BEESCRM:$addressInfo.address_detail}" id="addressDetail"/>
    </p>

    <div class="marginb-50"></div>
    <div class="btn-box">
        <input type="hidden" id="address_id" value="{BEESCRM:$addressInfo['address_id']}">
        <a href="javascript:void(0)" class="btn big" id="addAddr">提交</a>
    </div>
</div>

<include file="../commonJS"/>
<script type="application/javascript" src="/assets/repairhsd/js/apartment.js"></script>
<script>
    $(function () {
        //点击搜索园区、楼幢等联动
        ApartmentObj.init($('#community'),$('#building'),$('#floor'),$('#room'));
        $('#community').on('change',function () {
            ApartmentObj.communityChange();
        });
        $('#building').on('change',function () {
            ApartmentObj.buildingChange();
        });
        $('#floor').on('change',function () {
            ApartmentObj.floorChange();
        });
        $('#room').on('change',function () {
            ApartmentObj.roomChange();
        });

        //点击提交按钮
        $('#addAddr').on('click', function () {
            var address_id = $('#address_id').val();
            var real_name = $('#real_name').val();
            var mobile = $('#mobile').val();
            var verify_method = /1[3|4|5|7|8][0-9]{9}/;

            var community_id = $("#community").val();
            var community_name = $("#community").find("option:selected").text();
            var building_id = $("#building").val();
            var building_name = $("#building").find("option:selected").text();
            var floor_id = $('#floor').val();
            var floor_name = $('#floor').find("option:selected").text();
            var room_id = $('#room').val();
            var room_name = $('#room').find("option:selected").text();
            var address_detail = $.trim($("#addressDetail").val());

            if (!real_name || real_name == '') {
                $.alert('error', '请输入姓名');
                return false;
            }

            if(!mobile || mobile == ''){
                $.alert('error', '请输入手机号');
                return false;
            }

            if (!verify_method.test(mobile)) {
                $.alert('error', '请输入正确的手机号');
                return false;
            }

            if (!community_id || community_id == '0') {
                $.alert('error', '请选择园区');
                return false;
            } else if (!building_id || building_id == '0') {
                $.alert('error', '请选择楼幢');
                return false;
            } else if(!floor_id || floor_id == '0'){
                $.alert('error','请选择楼层');
                return false;
            } else if(!room_id || room_id == '0'){
                $.alert('error','请选择寝室');
                return false;
            }

            if(!floor_id || floor_id == '0'){
                floor_name = '';
            }

            var data = {
                'address_id': address_id,
                'real_name': real_name,
                'mobile': mobile,
                'community_id': community_id,
                'community_name': community_name,
                'building_id': building_id,
                'building_name': building_name,
                'floor_id': floor_id,
                'floor_name' : floor_name,
                'room_id': room_id,
                'room_name': room_name,
                'address_detail' : address_detail
            };

            $.ajax({
                url: "/Repairhsd/RepairhsdAddress/ajaxSaveNewAddr/repairId/{BEESCRM:$repairId}",
                type: 'post',
                data: data,
                dataType: 'json',
                success: function (data) {
                    if (data.status == 'S') {
                        $.alert('success', data.message);
                        setTimeout("location.href ='/Repairhsd/RepairhsdAddress/AddressList/repairId/{BEESCRM:$repairId}'", 2000);
                    } else {
                        $.alert('error', data.message);
                        return false;
                    }
                }
            });
        });
    });


</script>
</body>

</html>
